package com.ganzalang.gmall.designstrategy.discount.calculate;

import com.ganzalang.gmall.designstrategy.enums.DiscountTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @description: 折扣计算工厂选择器
 * @author: ganzalang
 */
@Service
@Slf4j
public class DiscountCalculatorSelector {

    /**
     * 折扣类型（有满件减价、满额减价、第N件打折、捆绑销售、搭售等等）
     * 用Map来做多实现类注入，key是beanName，value是beanName对应的bean
     */
    @Autowired
    private Map<String, DiscountCalculator> discountCalculatorMap;

    public DiscountCalculator create(DiscountTypeEnum discountType) {
        return discountCalculatorMap.get(discountType.getBeanName());
    }
}
